import type { IMenu } from '@/api/types/common'
import { renderIcon } from '@/utils/index'
import { OptionsSharp } from '@vicons/ionicons5'

const PATH_ICON_MAP = {
  '/admin/home/': renderIcon(OptionsSharp),
  '/admin/product': renderIcon(OptionsSharp),
  '/admin/order': renderIcon(OptionsSharp),
  '/admin/marketing': renderIcon(OptionsSharp),
  '/admin/cms': renderIcon(OptionsSharp),
  '/admin/system': renderIcon(OptionsSharp)
}
/**
 * 递归组装菜单格式
 */
export const transfromMenu = (originMenu: IMenu[]) => {
  return originMenu.map(menu => {
    const newMenu = {
      ...menu,
      key: menu.path,
      label: menu.title
    }
    if (menu.children) {
      newMenu.children = transfromMenu(menu.children)
    }
    if (menu.icon && PATH_ICON_MAP[menu.path]) {
      newMenu.icon = PATH_ICON_MAP[menu.path]
    } else {
      delete newMenu.icon
    }
    return newMenu
  })
}
